package com.insigma.business.qrcode.common.util;

import com.insigma.business.common.utils.CurrentUserUtil;
import com.insigma.business.qrcode.common.vo.*;

import java.util.Date;


public class SessionUtils {

    public static String getSoldierUserId() {
        SessionSoldier sessionSoldier = RpcContextUtil.getSessionSoldier();
        BizCheckUtil.checkNotNull(sessionSoldier, "用户非法");
        return sessionSoldier.getUserId();
    }

    public static SessionSoldier getSoldierUser() {
        SessionSoldier sessionSoldier = RpcContextUtil.getSessionSoldier();
        BizCheckUtil.checkNotNull(sessionSoldier, "用户非法");
        return sessionSoldier;
    }

    public static String getGovUserId() {
        //SessionGovEmployee sessionGovEmployee = RpcContextUtil.getSessionGovEmployee();
        //BizCheckUtil.checkNotNull(sessionGovEmployee, "用户非法");
        String soldierUserId = CurrentUserUtil.getCurrentUser().getUserId();
        return soldierUserId;
    }

    public static String getMerchantUserId() {
        SessionMerchantUser sessionMerchantUser = RpcContextUtil.getSessionMerchantUser();
        BizCheckUtil.checkNotNull(sessionMerchantUser, "用户非法");
        return sessionMerchantUser.getUserId();
    }

    public static String getCompanyUserId() {
        SessionCompanyUser sessionCompanyUser = RpcContextUtil.getSessionCompanyUser();
        BizCheckUtil.checkNotNull(sessionCompanyUser, "用户非法");
        return sessionCompanyUser.getUserId();
    }

    public static void buildCreatorOfGov(BaseInsertRequest<String> request) {
        request.setCreateDatetime(new Date());
        request.setCreatorType(UserTypeEnum.GOV_EMPLOYEE.name());
        request.setCreatorId(getGovUserId());
    }

    public static void buildCreatorOfSoldier(BaseInsertRequest<String> request) {
        request.setCreateDatetime(new Date());
        request.setCreatorType(UserTypeEnum.SOLDIER.name());
        request.setCreatorId(getSoldierUserId());
    }

    public static void buildCreatorOfCompany(BaseInsertRequest<String> request) {
        request.setCreateDatetime(new Date());
        request.setCreatorType(UserTypeEnum.COMPANY_USER.name());
        request.setCreatorId(getCompanyUserId());
    }

    public static void buildModifierOfGov(BaseUpdateRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.GOV_EMPLOYEE.name());
        request.setModifierId(getGovUserId());
    }

    public static void buildModifierOfSoldier(BaseUpdateRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.SOLDIER.name());
        request.setModifierId(getSoldierUserId());
    }

    public static void buildModifierOfCompany(BaseUpdateRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.COMPANY_USER.name());
        request.setModifierId(getCompanyUserId());
    }

    public static void buildDeleteOfGov(BaseDeleteRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.GOV_EMPLOYEE.name());
        request.setModifierId(getGovUserId());
    }

    public static void buildDeleteOfSoldier(BaseDeleteRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.SOLDIER.name());
        request.setModifierId(getSoldierUserId());
    }

    public static void buildDeleteOfCompany(BaseDeleteRequest<String,String> request) {
        request.setModifyDatetime(new Date());
        request.setModifierType(UserTypeEnum.COMPANY_USER.name());
        request.setModifierId(getCompanyUserId());
    }
}
